package b.h.z.utils;

import java.io.File;

import b.h.z.vo.Template;
import b.h.z.vo.Templates;

import com.thoughtworks.xstream.XStream;

public class ReadConfig {
	
	private static ClassLoader cl = null;
	
	static {
		cl = Thread.currentThread().getContextClassLoader();
		if (cl == null) {
			cl = ReadConfig.class.getClassLoader();
		}
	}
	
	public static Templates readConfig() {
		XStream xstream = new XStream();
		xstream.autodetectAnnotations(true);
		xstream.alias("ConfigTemplates", Templates.class);
		xstream.alias("ConfigTemplate", Template.class);
		Templates templates = (Templates) xstream.fromXML(new File(System.getProperty("user.dir") + "/templates.xml"));
		return templates;
	}
	
	public static Template readConfig(int idx) {
		return readConfig().getTemplates().get(0);
	}
	
	public static void main(String[] args) {
		Templates ts = readConfig();
		System.out.println(ts);
	}
}
